package com.example.md;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.inputmethodservice.InputMethodService;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import com.example.mmd.MobileClient;
import com.remote_control_mobile.remote_control.R;

public class PPTActivity extends Activity {
ImageButton minimizeBtn, maximizeBtn,prevBtn,nextBtn,v5;
static int show_picker;


String con_server="time-A.timefreq.bldrdoc.gov";
int port=13;
SocketTest st=new SocketTest("time-A.timefreq.bldrdoc.gov", 13);
static int inputcheck=0;
private InputMethodService Imm;
//public static MobileClient myClient;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    //	super.onCreate(savedInstanceState);
      /*
    	  InputMethodManager mgr = 
	           	    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
	         
	           	

	           	if (mgr != null&&show_picker==0) {
	            	    mgr.showInputMethodPicker();
	            	    show_picker=1;
	           	}
       */
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
      /*  
        try{
        	LoginActivity.myClient = new MobileClient("jin72&123","lore.cs.purdue.edu");
        }catch(Exception e){
        	Toast.makeText(getApplicationContext(), "Network fails", Toast.LENGTH_SHORT).show();
        }
 */
           	
          
      
		minimizeBtn = (ImageButton) findViewById(R.id.button1);
		maximizeBtn = (ImageButton) findViewById(R.id.button2);
		prevBtn = (ImageButton) findViewById(R.id.button3);
		nextBtn = (ImageButton) findViewById(R.id.button4);
		v5 = (ImageButton) findViewById(R.id.button5);

		v5.setImageResource(R.drawable.mpagenext);
		addListenerOnButton();
   
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    private void sendKey( int key )
    {
    //	LoginActivity.myClient.sendMsg("keyboard press " + key +"" );
	//	LoginActivity.myClient.sendMsg("keyboard release " + key + "" );
    	LoginActivity.myClient.sendMsg("keyboard press " + key +"" );
    	LoginActivity.myClient.sendMsg("keyboard release " + key + "" );
    }
 
    
	public void addListenerOnButton() {

		minimizeBtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				
				sendKey(27);
				 Toast toast = Toast.makeText(getApplicationContext(), st.getServerString(), Toast.LENGTH_LONG);
				 toast.show();
			}

		});
		maximizeBtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				
				sendKey(116);
				//Toast.makeText(getApplicationContext(), "button2", Toast.LENGTH_SHORT).show();
			}

		});
		prevBtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
		
				sendKey(37);
			//	Toast.makeText(getApplicationContext(), "button3", Toast.LENGTH_SHORT).show();
			}

		});
		nextBtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
	
				sendKey(39);
				//Toast.makeText(getApplicationContext(), "button4", Toast.LENGTH_SHORT).show();
			}
	

	});
	
	}
	public void sendMessage(View view){
	
		//Toast.makeText(getApplicationContext(), "button5", Toast.LENGTH_SHORT).show();
		Intent intent = new Intent(this,MouseActivity.class);
		startActivity(intent);
	}
	public void app_quit(View view){
		LoginActivity.myClient.sendMsg("QUIT" );
		System.exit(0);
	}
	
}
